<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>通过数据库升级表单</title>
  <link type="text/css" rel="stylesheet" th:href="@{${skinPath} + '/css.css'}" />
  <link href="index.css" rel="stylesheet" type="text/css">
  <script th:src="@{/inc/common.js}"></script>
  <script th:src="@{/js/jquery-1.9.1.min.js}"></script>
  <script th:src="@{/js/jquery-migrate-1.2.1.min.js}"></script>
  <link rel="stylesheet" th:href="@{/js/bootstrap/css/bootstrap.min.css}" />
  <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}" media="all">
  <script th:src="@{/js/bootstrap/js/bootstrap.min.js}"></script>
  <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
  <link th:href="@{/js/select2/select2.css}" rel="stylesheet"/>
  <script th:src="@{/js/select2/select2.js}"></script>
  <link th:href="@{/js/jquery-showLoading/showLoading.css}" rel="stylesheet" media="screen"/>
  <script type="text/javascript" th:src="@{/js/jquery-showLoading/jquery.showLoading.js}"></script>
  <script th:src="@{/js/jquery-alerts/jquery.alerts.js}" type="text/javascript"></script>
  <script th:src="@{/js/jquery-alerts/cws.alerts.js}" type="text/javascript"></script>
  <link th:href="@{/js/jquery-alerts/jquery.alerts.css}" rel="stylesheet" type="text/css" media="screen"/>
</head>
<body>
<div style="text-align:center;margin:20px">
  <input type="button" value="上一步" class="btn btn-default" onclick="window.location.href='dataDict'"/>&nbsp;&nbsp;
  <strong>
    同步表单&nbsp;&nbsp;
    数据源</strong>
  <select id="dbSource" name="dbSource">
    <option value="">请选择</option>
<!--    <option th:value="${diName}">[[${diName}]]</option>-->
    <option th:each="di : ${diInfo}"
            th:value="${di.name}"
            th:selected="${di.isDefault}"
            th:text="${di.name}">
    </option>
  </select>
  &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="if ('oa'==$('#dbSource').val()) {alert('不能修改默认的数据源oa'); return;} openWin('dbConnEdit?dbSource=' + $('#dbSource').val(), 640, 480)">修改数据源</a>
  &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="btn btn-default" value="确定" onclick="window.location.href='upgradeFormByDb?dbSource=' + o('dbSource').value;"/>
</div>
<div style="margin-left: 20px">
  注意本应用为旧版数据库，其它数据源为新版数据库<br/>
  新增表单可从新版系统的”表单管理”界面导出，导出时会自动带入基础数据及关联的流程，导入本应用后，流程将会显示在流程类型的”解决方案“中
</div>
<script>
  $('#dbSource').val("[(${dbSource})]");
</script>
<th:block th:if="${!ifDbSource}"}>
<table cellSpacing="0" cellPadding="3" width="95%" align="center" class="tabStyle_1">
  <tr>
    <td class="tabStyle_1_title" width="20%">编码</td>
    <td class="tabStyle_1_title" width="30%">新版</td>
    <td class="tabStyle_1_title" width="30%">本版</td>
    <td class="tabStyle_1_title" width="20%">操作</td>
  </tr>

  <tr th:each="co: ${codeInfo}">
    <td th:text="${co.codeNew}"></td>
    <td th:text="${co.nameNew}"></td>
    <th:block th:if="${co.isFound}">
      <td th:text="${co.name}"></td>
    </th:block>
    <td>
    <th:block if="${co.isFound}">
      <button class="btn btn-default" th:onclick="sync('[(${co.code})]', '[(${co.nameNew})]')">同步</button>
      &nbsp;&nbsp;
      <button class="btn btn-default" th:onclick="window.open('upgradeModuleByDb?dbSource=[(${dbSource})]&formCode=[(${co.code})]')">模块</button>
    </th:block>
    </td>
  </tr>
</table>
</th:block>
</body>
<script>
  function sync(formCode, name) {
    layer.confirm('您确定要同步"' + name + '"么？', {icon: 3, title: '提示'}, function (index) {
      layer.close();
      // if (!r) {
      //   return;
      // }

      $.ajax({
        type: "post",
        url: "upgradeFormByDbBtn",
        data: {
          op: "syncForm",
          formCode: formCode,
          dbSource: '[[${dbSource}]]'
        },
        dataType: "html",
        beforeSend: function (XMLHttpRequest) {
          $("body").showLoading();
        },
        success: function (data, status) {
          data = $.parseJSON(data);
          layer.msg(data.msg, {
            // window.location.reload();
          });
        },
        complete: function (XMLHttpRequest, status) {
          $("body").hideLoading();
        },
        error: function (XMLHttpRequest, textStatus) {
          // 请求出错处理
          alert(XMLHttpRequest.responseText);
        }
      });
    });
  }
</script>
</html>
